<?php
/**
 * Hoa Framework
 *
 *
 * @license
 *
 * GNU General Public License
 *
 * This file is part of HOA Open Accessibility.
 * Copyright (c) 2007, 2008 Ivan ENDERLIN. All rights reserved.
 *
 * HOA Open Accessibility is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * HOA Open Accessibility is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with HOA Open Accessibility; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *
 * @category    Framework
 * @package     Hoa_Framework
 *
 */

/**
 * Hoa_Framework
 */
require_once 'Framework.php';

/**
 * Hoathis_Twitter_Exception
 */
importModule('Twitter.Exception');

/**
 * Class Hoathis_Twitter_Decorator_Abstract
 *
 * @author      Gregory DARCHE <tetardo@gmail.com>
 * @copyright   Copyright (c) 2009 Life In The Cloud. http://lifeinthecloud.fr
 * @license     http://gnu.org/licenses/gpl.txt GNU GPL
 * @since       PHP 5
 * @version     0.1
 * @package     Hoathis_Twitter
 * @subpackage  Hoathis_Twitter_Decorator
 */
abstract class Hoathis_Twitter_Decorator_Abstract {

    /**
     * HTML output.
     *
     * @var String
     */
    public $html = '';

    /**
     * Search Tweet Regex
     *
     * @var Array
     */
    protected $search = array(
        '#http://[a-z0-9._/-]+#i',
        '#https://[a-z0-9._/-]+#i',
        '#ftp://[a-z0-9._/-]+#i',
        '#@([a-z0-9_]+)#i',
        '#\#([a-z0-9_-]+)#i',
        '#(RT )#i'
    );

    /**
     * Replace Tweet Regex
     *
     * @var Array
     */
    protected $replace = array();

    /**
     * Make render
     *
     * @access  protected
     * @param   Array   $data   Tweet.
     * @return  String
     */
    abstract protected function render ( $data = array() );

    /**
     * __construct
     *
     * @access  pubmic
     * @param   Array   $data   Tweet.
     */
    public function __construct( $data = array() ){

        $data->text_html = nl2br($data->text);
        $data->text_html = preg_replace ($this->search, $this->replace, $data->text_html);

        if ($data->truncated)
            $data->text_html.= '...';

        $this->html = $this->render($data);
    }

    /**
     * __toString
     *
     * @access  public
     * @return  String  HTML output
     */
    public function __toString() {

        return $this->html;
    }
}
